package org.example.slave.packet;

import lombok.Data;
import lombok.EqualsAndHashCode;
import org.example.slave.util.ByteUtil;

/**
 * @author dingrui
 * @since 2022/2/16
 * @description
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class ResultSetHeaderPacket extends PacketWithHeader {

    private long columnCount;
    private long extra;

    @Override
    public void fromBytes(byte[] data) {
        int index = 0;
        byte[] colCountBytes = ByteUtil.readBinaryCodedLengthBytes(data, index);
        columnCount = ByteUtil.readLengthCodedBinary(colCountBytes, index);
        index += colCountBytes.length;
        if (index < data.length - 1) {
            extra = ByteUtil.readLengthCodedBinary(data, index);
        }
    }
}
